package ws.jdbc.concurrent.driver.sqlserver.tds;

import java.nio.ByteBuffer;

/**
 * Handles the {@code ERROR} token reading process.
 *
 * The stream definition of the {@code ERROR} token is the same as the {@code
 * INFO} token, so this reader extends the {@link InfoTokenReader} to provide
 * the same functionality.
 *
 * @author Wilson Santos, 36228 <wilson.santos@ua.pt>
 */
class ErrorTokenReader extends InfoTokenReader {

  /**
   * Create a new reader instance.
   *
   * @param stream data input stream to read the token from.
   */
  ErrorTokenReader(final ByteBuffer stream) {
    super(stream);
  }

  /**
   * Get the SQL error state.
   *
   * @return SQL error state.
   */
  String getSQLState() {
    return String.valueOf(errorState);
  }

  /**
   * Get the message explaining the error.
   *
   * @return message explaining the error.
   */
  String getReason() {
    return msgText;
  }
}
